package com.cskaoyan.service.wx;

import com.cskaoyan.bean.wx.WxTopic;
import com.cskaoyan.bean.wx.WxTopicDetail;
import com.cskaoyan.bean.wx.WxTopicExample;
import com.cskaoyan.bean.wx.WxTopicListBean;
import com.cskaoyan.mapper.wx.WxTopicMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class WxTopicServiceImpl implements WxTopicService {

    @Autowired
    WxTopicMapper wxTopicMapper;

    @Override
    public WxTopicListBean queryWxTopicListBean(Integer page, Integer size) {
        //分页
        PageHelper.startPage(page, size);
        //提供条件,查询
        WxTopicExample wxTopicExample = new WxTopicExample();
        List<WxTopic> wxTopics = wxTopicMapper.selectByExample(wxTopicExample);
        PageInfo pageInfo = new PageInfo(wxTopics);
        long count = pageInfo.getTotal();
        //返回值
        WxTopicListBean wxTopicListBean = new WxTopicListBean();
        wxTopicListBean.setData(wxTopics);
        wxTopicListBean.setCount(count);
        return wxTopicListBean;
    }

    @Override
    public WxTopicDetail queryWxTopicDetailById(Integer id) {
        WxTopic topic = wxTopicMapper.selectByPrimaryKey(id);
        WxTopicDetail wxTopicDetail = new WxTopicDetail();
        wxTopicDetail.setTopic(topic);

        //goods不知道是什么所以先封装空list
        ArrayList arrayList = new ArrayList();
        wxTopicDetail.setGoods(arrayList);

        return wxTopicDetail;
    }

    @Override
    public List queryWxTopicRelatedById(Integer id) {
        ArrayList list = new ArrayList();
        WxTopic topic = wxTopicMapper.selectByPrimaryKey(264);
        list.add(topic);
        topic = wxTopicMapper.selectByPrimaryKey(266);
        list.add(topic);
        topic = wxTopicMapper.selectByPrimaryKey(268);
        list.add(topic);
        topic = wxTopicMapper.selectByPrimaryKey(271);
        list.add(topic);
        return list;
    }
}
